<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章列表--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../js/layui/css/layui.css"
	media="all" />
<script src="../../js/layui/layui.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="../../css/news.css" media="all" />
<style type="text/css">
.layui-table-cell {
	text-align: center;
	height: auto;
	white-space: normal;
	width: auto;
}
</style>
</head>
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-sm" lay-event="edit" ><i class="layui-icon layui-icon-edit"></i>订单详情</a>
<a class="layui-btn layui-btn-sm" lay-event="deliver" ><i class="layui-icon layui-icon-edit"></i>发货</a>
</script>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<div class="layui-form-item"
			style="margin-top: 10px; margin-left: 10px">
			<form class="layui-form" method="post" onsubmit="return false;">
				<label class="layui-form-mid">订单编号:</label>
				<div class="layui-input-inline" >
					<input type="text" id="name" name="orderId" placeholder="请输入产品名"
						autocomplete="off" class="layui-input">
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">下单时间</label>
					<div class="layui-input-inline" style="width: 100px;">
						<input type="text" name="orderTime" id="startTime"
							autocomplete="off" class="layui-input">
					</div>
					<label class="layui-form-label">支付时间</label>
					<div class="layui-input-inline" style="width: 100px;">
						<input type="text" name="paymentTime" id="endTime"
							autocomplete="off" class="layui-input">
					</div>
					<div class="layui-inline">
					<button class="layui-btn" id="search" data-type="reload">搜索</button>
				</div>
			</form>
		</div>
	</blockquote>
	<div class="layui-form news_list">
		<table class="layui-table" id="news" lay-filter="table">
		</table>
	</div>
	<script type="text/javascript">
		layui.use([ 'table', 'layer', 'form','laydate' ],function() {
							var table = layui.table
							, $ = layui.$
							, layer = layui.layer
							, laydate = layui.laydate
							, form = layui.form;
							//获取产品类别
							$.post("http://localhost:8080/Greenleaf/order/getAll",
									function(res) {
									  if (res!=null) {
										$("#sort").empty();
										$("#sort").append(new Option("请选择", "0"));
										$.each(res.data,function(index, item) {
											$("#sort").append(new Option(item.className,item.pdtClassId));
											
											});
									} else {
										
										$("#sort").append(new Option("暂无数据", ""));
									}
									  form.render();//重新渲染一下表单
								}, "json");
							laydate.render({ 
								  elem: '#startTime'
								  ,type: 'datetime'
								});
							laydate.render({ 
								  elem: '#endTime'
								  ,type: 'datetime'
								});
							// 允许为空                                                                       
							table.render({
										elem : '#news',
										url : 'http://localhost:8080/Greenleaf/order/getAll',//数据接口
										page : true, 
										limit:3,
										limits:[3,5,7,10],
										cols : [ [ //表头
										{type : 'checkbox'}
										,{field : 'orderId',title : '编号',sort : true}
										,{field : 'orderNumber',title : '订单号'}
										,{field : 'vId',title : '所属会员'}
										,{field : 'orderTime',title : '下单时间'}
										,{field : 'total',title : '总金额'}
										,{field : 'orderText',title : '订单备注'}
										,{field : 'paymentState',title : '支付状态'}
										,{field : 'masterState',title : '主状态'}
										,{field : 'branchState',title : '辅状态'}
										,{field : 'paymentTime',title : '支付时间'}
										,{field : 'paymentMode',title : '支付方式'}
										,{field : 'eTime',title : '过期时间'}
										,{title : '操作',align : 'center',fixed : 'right',toolbar : '#barDemo'}
										] ],
										id : "ProductReload"
									});
							$("#search").click(
											function() {
												table.reload('ProductReload',
														{
																url : 'http://localhost:8080/Greenleaf/order/getAll',//条件分页查询
																page : {
																curr : 1
																//重新从第 1 页开始
																	},
																	where : {
																		name : $("#name").val()
																		,sort : $("#sort").val()
																		,startTime : $("#startTime").val()
																		,endTime : $("#endTime").val()
																		,alternative1 : $("#alternative1").val()
																	}
																});
											});
							
							table.on('tool(table)',function(obj) {
												var data = obj.data; 
												var layEvent = obj.event; 
												var tr = obj.tr; 
												sessionStorage.setItem("order",JSON.stringify(data));
												 if (layEvent === 'edit') { //编辑
													var id = data.dId;
													var index = layui.layer
															.open({
																title : "产品详情",
																type : 2,
																area: ['900px', '500px'],
																content : "orderDetail.html",
																success : function(
																		layero,
																		index) {
																	layui.layer
																			.tips(
																					'点击此处返回产品列表',
																					' .layui-layer-close',
																					{
																						tips : 3
																					});
																},
																end : function() {
																	location.reload();
																}
															})

												}else if(layEvent === 'deliver'){
													$.post('http://localhost:8080/Greenleaf/order/update',//添加商品
																	{"orderId" : data.orderId,
																	"masterState" : "待收货"
																	},function(res){
																if (res) {
																	var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
															        setTimeout(function(){
															            top.layer.close(index);
																		top.layer.msg("发货成功！");
															 			layer.closeAll("iframe");
																 		parent.location.reload();
															        },1000);
																}else{
																	var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
															        setTimeout(function(){
															            top.layer.close(index);
																		top.layer.msg("发货失败！");
															        },1000);
																}
															},"text"
													)
													
												}
											});
							$("#batchDel").click(function() {
								var checkStatus = table.checkStatus('ProductReload'); //idTest 即为基础参数 id 对应的值
								var allData = checkStatus.data;
								var ids = "";
								//循环遍历取设计师编号
								for (var i = 0; i < allData.length; i++) {
									if (i == allData.length - 1) {
										ids += allData[i].pdtId;
									} else {
										ids += allData[i].pdtId
												+ ",";
									}
								}
								if (ids == "") {
									layer.msg("请选择要删除的数据！");
									return false;
								}
								layer.confirm('确定要删除吗',
									function(index) {
										$.post("http://localhost:8080/Greenleaf/product/dels",
											{ids : ids
											},function(res) {
												if (res.success) {
													layer.msg('删除成功',{
														icon : 1,
														time : 1500
													});
												//刷新页面
												location.reload();
												} else {
													layer.msg('删除失败',{
														icon : 2,
														time : 1500
													});
												}
											},"json")
										})
									})
						})
	</script>
</body>
</html>